package com.swq.java.code.chapter18.code24;

import com.swq.java.code.utils.Values;

import java.io.*;
import java.nio.*;
import java.nio.channels.*;
import java.nio.charset.*;

public class BigFileTester {
    public static void main(String args[]) throws IOException {
        int capacity = 0x8000000; //128M
        MappedByteBuffer mb = new RandomAccessFile(Values.testFileName, "rw")
                .getChannel()
                .map(FileChannel.MapMode.READ_WRITE, 0, capacity);
        mb.put("你好啊".getBytes("GBK"));  //向文件中写入采用GBK编码的字符串“你好啊”
        mb.flip();
        System.out.println(Charset.forName("GBK").decode(mb));
    }
}